﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;

//namespace SelectServer
//{
//    class EventDispath
//    {
//    }
//}

//using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace SelectServer
{

    delegate void EventDelagate(SelectServer.ClientMsgUnPack msg);

    class EventNode
    {
        public int m_EventID;
        public SelectServer.ClientMsgUnPack msg;
    }

    class EventDispath
    {
        public static int g_MaxEventNum = 300;
        List<EventDelagate>[] m_Event;
        Queue<EventNode> m_EventQueue;
        public EventDispath()
        {
            m_Event = new List<EventDelagate>[g_MaxEventNum];
            m_EventQueue = new Queue<EventNode>();
        }

        public void RegistEvent(int eventID, EventDelagate func)
        {
            if (null == m_Event[eventID])
            {
                m_Event[eventID] = new List<EventDelagate>();
            }
            m_Event[eventID].Add(func);
        }

        public void AddEvent(EventNode eventNode)
        {
            m_EventQueue.Enqueue(eventNode);
        }

        public void Proccess()
        {
            if (0 != m_EventQueue.Count)
            {
                EventNode mCur = m_EventQueue.Dequeue();
                if (null == m_Event[mCur.m_EventID])
                {
                    //Debug.Print("event ID: " + mCur.m_EventID + " is null");
                    Debug.Print("event ID: " + mCur.m_EventID + " is null");
                }
                else
                {
                    List<EventDelagate> curEventDelagate = m_Event[mCur.m_EventID];
                    for (int i = 0; i < curEventDelagate.Count; ++i)
                    {
                        curEventDelagate[i](mCur.msg);
                    }
                }
            }
        }
    }
}



